$(function() {
    query();
});

function query(){
    $('#orderTab').bootstrapTable({
        method : 'get',
        url : "/showOrders",
        striped : true,
        pageNumber : 1,
        pagination : true,
        sidePagination : 'client',
        pageSize : 5,
        pageList : [ 5, 10, 15, 20 ],
        showRefresh : true,
        search:true,
        smartDisplay:true,
        detailView:true,
        columns : [
            {
                title : '订单编号',
                field : 'id',
                align : 'center',
                width:"20px",
            },{
                title : '商品',
                field : 'itemBo.title',
                align : 'center',
                width:"20px",
            },{
                title : '交易量',
                field : 'itemAmount',
                align : 'center',
                width:"20px",
            }, {
                title : '交易额',
                field : 'orderPrice',
                align : 'center',
                width:"20px",
            } ,{
                title : '操作',
                width : 123,
                field : 'operate',
                align : 'center',
                width:"20px",
                formatter : function(value, row, index) {
                    var value =
                        "<a href='javascript:;' onclick='selectOrder("+row.id+")'>订单轨迹</a>"+"   "+
                        "<a href='javascript:;' onclick='deleteOrder("+row.id+")'>订单删除</a>";
                    return value;
                }
            } ]
    })
}


function deleteOrder(id) {
    if (confirm('是否删除？')) {
        $.ajax({
            url: '/deleteOrder',
            type: "POST",
            data: {
                id:id,
            },
            success: function (data) {
                if(data.status=="fail"){
                    alert(data.data);
                    location.reload(false);
                }else{
                    alert(data.data);
                    location.reload(false);
                }
            }
        });
    }
}


function selectOrder(id){
    layer.open({
        type : 2,
        title : '订单轨迹',
        maxmin : true,
        shadeClose : false, // 点击遮罩关闭层
        /*area : [ '850px', '550px' ],*/
        area: [ '50%', '95%' ],
        content :"/toOrderDetial?id="+id+"&flag=2"
    });
}